﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>生产计划-新建退料单</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<script type="text/javascript">

$(document).ready(function() {
	$.validator.setDefaults({
		submitHandler: function(validator, form) {
			var isError = saveSubmit();
			if (!isError) {
				form.submit();
			}
			return false;
		}
	});
	$("#saveBackMaterialRequisiteForm").validate();
});

function checkValue(id) {
	var outStoreVlue = parseFloat($("#outStoreNumbers-" + id).html());
	var qualifiedValue = parseFloat($("#qualifiedBackNums-" + id).val());
	var unqualifiedValue = parseFloat($("#unqualifiedBackNums-" + id).val());
	if ((qualifiedValue + unqualifiedValue) > outStoreVlue) {
		alert("总的退料数量不能大于可退料数量");
	}
}

function saveSubmit() {
	var isError = false;
	$("span[id^='outStoreNumbers-']").each(function(i){
		var id = this.id;
		var outStoreVlue = parseFloat($(this).html());
		var qualifiedId = id.replace("outStoreNumbers-", "qualifiedBackNums-");
		var qualifiedValue = parseFloat($("#" + qualifiedId).val());
		var unqualifiedId = id.replace("outStoreNumbers-", "unqualifiedBackNums-");
		var unqualifiedValue = parseFloat($("#" + unqualifiedId).val());
		if ((qualifiedValue + unqualifiedValue) > outStoreVlue) {
			isError = true;
		}
	});
	if (isError) {
		alert("总的退料数量不能大于可退料数量");
	}
	return isError;
}

</script>
</HEAD>
<BODY>
    <s:form action="saveBackMaterialRequisiteForm">
    <s:hidden name="formId" value="%{mrForm.id}" />
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">生产计划</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">新建退料单</span></td>
		  </tr>
		</table>
      </div>
     <div class="main_1">
       <table width="99%" border="0" cellpadding="5" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="4">领料单信息</td>
         </tr>
         <tr>
		    <td width="20%" bgcolor="#FAFAFA" align="right"><strong>单号</strong></td>
		    <td width="30%" bgcolor="#FAFAFA"><s:property value="mrForm.id"/></td>
		    <td width="20%" bgcolor="#FAFAFA" align="right"><strong>部门</strong></td>
	        <td width="30%" bgcolor="#FAFAFA"><s:property value="mrForm.deptName"/></td>
		 </tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>日期</strong></td>
	      <td bgcolor="#FAFAFA"><s:date name="mrForm.createDate" format="yyyy-MM-dd"/></td>
	      <td bgcolor="#FAFAFA" align="right"><strong>生产批号</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="mrForm.planNo"/></td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>经办人</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="mrForm.person"/></td>
	      <td bgcolor="#FAFAFA" align="right"><strong>状态</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="mrForm.statusName"/></td>
		</tr>
       </table>
     </div>
     <div class="clear"></div>
	 <div class="main_scroll">
       <table width="930px" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a" id="productList">
        <tr class="ksglxx2bg">
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
          <th width="180px" >其他</th>
		  <th width="50px">单位</th>
		  <th width="95px" >可退料数量</th>
		  <th width="95px">合格退料数量<span class="red-text1">*</span></th>
		  <th width="105px">不合格退料数量<span class="red-text1">*</span></th>
		</tr>
		<s:iterator value="mrForm.formDetails" id="detail" status="st">
          <s:if test="#st.Odd">
            <tr class="odd">
          </s:if>
          <s:else>
            <tr class="even">
          </s:else>
              <td><s:property value="#detail.materialRootCategory" /></td>
              <td><s:property value="#detail.materialCategory" /></td>
              <td><s:property value="#detail.materialName" /></td>
              <td><s:property value="#detail.materialType" /></td>
              <td><s:property value="#detail.materialSku" />
                  <s:hidden name="materialIds" value="%{#detail.materialId}" /></td>
              <td><s:property value="#detail.unit" /></td>
              <td><span id='outStoreNumbers-<s:property value="#st.index" />'><s:property value="%{#detail.realNumber - #detail.backNumber}" /></span>
                  <s:hidden name="maxBackNumbers" value="%{#detail.realNumber - #detail.backNumber}" /></td>
              <td><s:textfield id='qualifiedBackNums-%{#st.index}' 
              				name="qualifiedBackNums" size="5" 
              				cssClass="{required:true,maxlength:5,number:true}"
              				onblur="checkValue('%{#st.index}')" /></td>
              <td><s:textfield id='unqualifiedBackNums-%{#st.index}' 
              				name="unqualifiedBackNums" size="5" 
              				cssClass="{required:true,maxlength:5,number:true}"
              				onblur="checkValue('%{#st.index}')" /></td>
            </tr>
		</s:iterator>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="45%" align="right">
			   <s:submit value="保存" cssClass="input1" />&nbsp;&nbsp;
			   <input type="button" value="关闭" class="input1" onclick='javascript:window.location.href="materialRequisiteFormList.action"' /></td>
			 <td width="55%" align="left"></td>
		   </tr>
	   </table>
	</div>
	<div class="clear"></div>
	</s:form>
</BODY></HTML>
